package kos.robert.core;

import java.awt.*;
import java.awt.event.*;

public class MouseInput extends Core implements KeyListener, MouseMotionListener, MouseListener, MouseWheelListener {
	public static void main(String[] args) {
		new MouseInput().run();
	}

	private String messasge = "";

	// init calls super init
	public void init() {
		super.init();
		Window window = screen.getFullScreenWindow();
		window.addMouseListener(this);
		window.addMouseWheelListener(this);
		window.addMouseMotionListener(this);
		window.addKeyListener(this);
	}

	@Override
	public synchronized void draw(Graphics2D g) {
		Window window = screen.getFullScreenWindow();
		g.setColor(window.getBackground());
		g.fillRect(0, 0, screen.getWidth(), screen.getHeight());
		g.setColor(window.getForeground());
		g.drawString(messasge, 40, 50);
	}

	// mouse listeners interface
	@Override
	public void mousePressed(MouseEvent e) {
		messasge = "You pressed down the mouse";
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		messasge = "You released the mouse";
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	// mouse motion interface
	@Override
	public void mouseDragged(MouseEvent e) {
		messasge = "You are dragging the mouse";
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		messasge = "You are moving the mouse";
	}

	// wheel interface
	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		messasge = "You are moving the mouse wheel";
	}

	// keyPressed
	@Override
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		if (keyCode == KeyEvent.VK_ESCAPE) {
			stop();
		} else {
			messasge = "Pressed : " + KeyEvent.getKeyText(keyCode);
			// System.out.println(mess);
			e.consume();
		}
	}

	// keyReleased
	@Override
	public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		messasge = "Released : " + KeyEvent.getKeyText(keyCode);
		// System.out.println(mess);
		e.consume();
	}

	@Override
	public void keyTyped(KeyEvent e) {
		e.consume();
	}
}
